package com.itheima.reggie.controller;

import com.itheima.reggie.common.R;
import com.itheima.reggie.sms.SendSmsUtil;
import com.itheima.reggie.utils.ValidateCodeUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;

import javax.servlet.http.HttpSession;

/**
 * @author ghy
 * @version v1.0
 * create on 2022/11/21 15:55
 */
//@RestController
//@RequestMapping("/sms")
@Slf4j
public class SmsController {

    @Autowired
    private SendSmsUtil sendSmsUtil;

    /**
     * 发送验证码
     * @param session
     * @param phone
     * @return
     * @throws Exception
     */
    @GetMapping("/send")
    public R send(HttpSession session, String phone) throws Exception {
        //1.生成验证码并保存Session
        String code = ValidateCodeUtils.generateCode(4);
        session.setAttribute("app_login_code:" + phone, code);
        //2.发送验证码
        //sendSmsUtil.sendMessage(phone, code, "SMS_254910142");
        log.warn("{}", code);
        return R.success(code);
    }

}
